<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	/*******main*******/
	$return['province']=file_get_contents(ROOT_D.'/core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	$spots=pdo_getall('jy_tour_spot',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
	if($spots){
		foreach($spots as &$item){
			$images=json_decode($item['images'],true);
			$item['destination_pcd']=json_decode($item['destination_pcd'],true);
			$item['thumb']=$images['0'];
			$item['sellnum']=pdo_count('jy_tour_order',array('uniacid'=>$_SESSION['uniacid'],'spot_id'=>$item['id'],'status >'=>'0'));
			$pingjianum=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'spot_id'=>$item['id']));
			$pinjia_good=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'spot_id'=>$item['id'],'star >'=>'3'));
			$item['manyidu']=$pingjianum?number_format($pinjia_good/$pingjianum,0)*100:100;
		}
	}
	$return['spots']=$spots;
	//print_r($return['province']);exit;
	exi($return);
}
if($_RQ['op']=='getlist'){
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$post=get_postdata();
	//print_r($post);exit;
	if(!empty($post['keyword'])){
		$params['title like']='%'.trim($post['keyword']).'%';
		$return['params']['title']=$post['params']['keyword'];
	}
	if(!empty($post['province'])){
		$params['province']=$post['province'];
		$return['params']['province']=$post['params']['province'];
	}
	if(!empty($post['city'])){
		$params['city']=$post['city'];
		$return['params']['city']=$post['params']['city'];
	}
	$fields=array('id','uniacid','title','status','price','createtime','images','destination_pcd');
	$spots=pdo_getslice('jy_tour_spot',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($spots){
		foreach($spots as &$item){
			$images=json_decode($item['images'],true);
			$item['destination_pcd']=json_decode($item['destination_pcd'],true);
			$item['thumb']=$images['0'];
			$item['sellnum']=pdo_count('jy_tour_order',array('uniacid'=>$_SESSION['uniacid'],'spot_id'=>$item['id'],'status >'=>'0'));
			$pingjianum=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'spot_id'=>$item['id']));
			$pinjia_good=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'spot_id'=>$item['id'],'star >'=>'3'));
			$item['manyidu']=$pingjianum?number_format($pinjia_good/$pingjianum,0)*100:100;
		}
	}
	
	//print_r($groups);exit;
	$return['spots']=$spots;
	
	exi($return);
}